package com.example.demo.service.impl;

import com.example.demo.entity.Result;
import com.example.demo.mapper.ButtonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

@Service
public class ButtonServiceImpl {
    @Autowired
    private ButtonMapper buttonMapper;

    public Result getAllButton(Map<String, Object> params) {
        List<Map<String,Object>> list=buttonMapper.getAllButton(params);
        int count=buttonMapper.getButtonCount();
        return Result.ok(list).setRecordsCount((long) count);
    }

    @Transactional
    public Result insertButton(Map<String, Object> params) {
        buttonMapper.insertButton(params);
        return Result.ok("保存按钮成功");
    }

    @Transactional
    public Result insertRoleButton(Map<String, Object> params) {
        //先删除
        buttonMapper.deleteRoleButton(params);
        if(Objects.nonNull(params.get("buttonList"))){
            List<String> list= (List<String>) params.get("buttonList");
            if(list.size()>0){
                buttonMapper.insertRoleButton(params);
            }
        }
        return Result.ok("配置按钮成功");
    }

    public Result getRoleButton(Map<String, Object> params) {
        List<Map<String,Object>> list=buttonMapper.getRoleButton(params);
        return Result.ok(list);
    }

    public Result getUserButton(Map<String, Object> params) {
        List<String> list=buttonMapper.getUserButton(params);
        return Result.ok(list);
    }
}
